package com.wwwarehouse.contract.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.contract.bean.CanSeePublishResourseBean;

import java.util.List;

import contract.wwwarehouse.com.contract.R;

/**
 * @创建者 chenchao.
 * @创建时间 2017/9/24 19:52
 * @描述 ${TODO}
 */

public class CanSeeLocalPublishAdapter extends BaseAdapter  {

    private Context mContext;
    private List<CanSeePublishResourseBean.TempPbResourcesBean> mTempPbResources;
    private int mHeight;
    public CanSeeLocalPublishAdapter(Context context, List<CanSeePublishResourseBean.TempPbResourcesBean> list, int height) {
        mContext = context;
        mTempPbResources = list;
        mHeight = height;
    }

    @Override
    public int getCount() {
        return mTempPbResources == null ? 0 : mTempPbResources.size();
    }

    @Override
    public Object getItem(int position) {
        return mTempPbResources.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    ViewHolder viewHolder;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final CanSeePublishResourseBean.TempPbResourcesBean tempPbResourcesBean = mTempPbResources.get(position);

        if (convertView == null) {
            convertView = parent.inflate(mContext, R.layout.see_publish_item, null);
            viewHolder = new ViewHolder();
            viewHolder.ivGood = (ImageView) convertView.findViewById(R.id.iv_good);
            viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tvDel = (TextView) convertView.findViewById(R.id.tv_del);
            convertView.setTag(viewHolder);
            AbsListView.LayoutParams params =  new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.height = mHeight;
            convertView.setLayoutParams(params);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BaseApplication.getApplicationInstance().displayImg(tempPbResourcesBean.getRsImg(), viewHolder.ivGood);
        viewHolder.tvName.setText(tempPbResourcesBean.getRsName());
//        viewHolder.tvDel.setOnTouchListener(this);
        viewHolder.tvDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到详情页
                Bundle detailBundle = new Bundle();
//                detailBundle.putString("itemType","H_SALE");
                detailBundle.putString("type", "0");
                detailBundle.putLong("ukid", tempPbResourcesBean.getRsDefinedUkid());
                detailBundle.putLong("buid", tempPbResourcesBean.getBuId());
                ((BaseCardDeskActivity) mContext).pushFragment(
                        (Fragment) ARouter.getInstance().build("/ResourceCenter/InfomationResourcesFragment").with(detailBundle).navigation());

            }
        });

        return convertView;
    }

//    @Override
//    public boolean onTouch(View v, MotionEvent event) {
//        if (event.getAction() == MotionEvent.ACTION_DOWN) {
//            viewHolder.tvDel.setTextColor(mContext.getResources().getColor(R.color.common_color_c6_585d62));
//        } else if (event.getAction() == MotionEvent.ACTION_UP) {
//            viewHolder.tvDel.setTextColor(mContext.getResources().getColor(R.color.common_color_c7_96999e));
//        }
//        return true;
//    }

    static class ViewHolder{
        private ImageView ivGood;
        private TextView tvName;
        private TextView tvDel;
    }
}
